use std::fs::File;
use std::io::ErrorKind;

pub fn open_file() -> bool {
    let _file = File::open("test.txt").unwrap_or_else(|error| {
        if error.kind() == ErrorKind::NotFound {
            File::create("text.txt").unwrap_or_else(|error| {
                panic!("Problem creating the file: {:?}", error);
            })
        } else {
            panic!("Problem opening the file: {:?}", error);
        }
    });
    return true;
}

pub fn open_file_match() -> bool {
    let f = File::open("abc.txt");
    let _f = match f {
        Ok(file) => file,
        Err(error) => match error.kind() {
            ErrorKind::NotFound => match File::create("abc.txt") {
                Ok(fc) => fc,
                Err(e) => {
                    panic!("Problem creating the file: {:?}", e);
                }
            },
            _ => {
                panic!("Problem opening the file: {:?}", error);
            }
        },
    };
    return true;
}